package com.photoeditor.demo.ui.widget.image.magazine;

import android.app.ProgressDialog;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.LinearLayout;

import com.photoeditor.R;
import com.photoeditor.demo.db.MagazineBean;
import com.photoeditor.demo.ui.activity.edit.EditorImageActivity;
import com.photoeditor.demo.ui.widget.HorizontalListView;
import com.photoeditor.demo.ui.widget.collage.IMagazineTemplateChangeListener;

import java.util.ArrayList;


public class EditMagazineTempletBar extends LinearLayout {

    public HorizontalListView mListView;
    //    public EditMagazineListAdapter mMagazineListAdapter;
    IMagazineTemplateChangeListener listener;
    //记录上次点击的位置
    private int mPrePosition = -1;
    private EditorImageActivity mContext;
    private ProgressDialog mWaitProgressDialog;
    private EditMagazineCollageRelativeLayout mMagazineView;
    private ArrayList<MagazineBean> mMagazineDatas;

    public EditMagazineTempletBar(Context context) {
        this(context, null);
    }

    public EditMagazineTempletBar(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public EditMagazineTempletBar(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        mContext = (EditorImageActivity) context;
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        mListView = (HorizontalListView) findViewById(R.id.edit_magazine_listview);

    }

    public void init(IMagazineTemplateChangeListener magazineTempletChangeListener) {
//        listener=magazineTempletChangeListener;
//        mMagazineListAdapter = new EditMagazineListAdapter(getContext());
//        mMagazineListAdapter.setSourceBitmapSize(1);
//        mListView.setAdapter(mMagazineListAdapter);
//        mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
//            @Override
//            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//                if (mPrePosition==position) return;
//                if (mContext.isLoadingMagazineProgressShowing())return;
//                mContext.showLoadingMagazineProgress();
//                mPrePosition=position;
//                mMagazineListAdapter.setSelectedPosition(position,view);
//                Bitmap item = mMagazineListAdapter.getItem(position);
//                int width = item.getWidth();
//                int height = item.getHeight();
//                float scale=  (float) (width*1.0/height);
//                listener.magazineTemplateChange(item,position,scale);
//            }
//        });
    }

    public void dismissWaitingDailog() {
        if (mWaitProgressDialog != null && mWaitProgressDialog.isShowing()) {
            mWaitProgressDialog.dismiss();
        }
    }

    public void setMagazineView(EditMagazineCollageRelativeLayout magazineView) {
        mMagazineView = magazineView;
    }

    public void onDestory(boolean isActFinish) {
//        if (mMagazineListAdapter!=null){
//            mMagazineListAdapter.onDestory(isActFinish);
//        }
    }
}
